
#include <bits/stdc++.h>
using namespace std;

int main() {
  int n, lock, l = 0, r = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> lock;
    if (lock == 1 && l == 0) {
      l = i;  //l：最左边的位置
    }
    if (lock == 1) {
      r = i; //r：最右边的位置
    }
  }
  cout << r - l << endl;

  return 0;
}